package com.google.appengine.api.datastore;

import lombok.Getter;
import org.apache.hadoop.conf.Configuration;

/**
 *
 * @author Secondary User
 */
public class DatastoreServiceConfig
{
	private static final double DEFAULT_DEADLINE = 5;
	private static Configuration cfg;
	private static String appName;
	
	@Getter
	private double deadline = DEFAULT_DEADLINE; //Seconds
	@Getter
	private final ReadPolicy readPolicy;
	@Getter
	private final Type type;
	@Getter
	private final Configuration config;
	@Getter
	private final String applicationName;

	public DatastoreServiceConfig(ReadPolicy readPolicy, Type type)
	{
		this.readPolicy = readPolicy;
		this.type = type;
		this.config = cfg;
		this.applicationName = appName;
	}

	public static void setHBaseConfiguration(Configuration config)
	{
		cfg = config;
	}

	public static void setApplicationName(String applicationName)
	{
		appName = applicationName;
	}

	public void deadline(Double deadline)
	{
		if (deadline == null)
		{
			this.deadline = DEFAULT_DEADLINE;
		}
		else
		{
			this.deadline = deadline;
		}
	}

	public static class Builder
	{

		public static DatastoreServiceConfig withReadPolicy(ReadPolicy readPolicy)
		{
			return new DatastoreServiceConfig(readPolicy, Type.HBASE);
		}

		public static DatastoreServiceConfig withDefaults()
		{
			return withReadPolicy(new ReadPolicy(ReadPolicy.Consistency.STRONG));
		}
	}

	public static enum Type
	{

		HBASE;
	}
}
